package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hulk.ratel.common.constant.enums.YesOrNo;
import com.hulk.ratel.persistence.entity.DictCode;
import com.hulk.ratel.persistence.repository.IDictCodeRepository;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * Created by cmt on 2018/08/03.
 * 字典codeCache
 */
@Slf4j
@Component
public class DictCodeCache {

    @Autowired
    private IDictCodeRepository dictCodeRepository;

    //@Cacheable(value = "dictCodeCache", key = "#dictId+ 'DictCodeCache_findDictCodes'")
    //@Cached(name="DictCodeCache.findDictCodes", key = "#dictId + 'DictCodeCache_findDictCodes'", cacheType = CacheType.BOTH ,localLimit = 4096, localExpire =600 ,expire = 600)
    @Cached(name="DictCodeCache.findDictCodes", key = "#dictId + 'DictCodeCache_findDictCodes'", cacheType = CacheType.LOCAL , expire =600 )
    public java.util.List<DictCode> findDictCodes( @NonNull String dictId) {
        DictCode dcParam = new DictCode();
        dcParam.setDictId(dictId);
        dcParam.setCodeFlag(YesOrNo.YES.getValue());
        Wrapper<DictCode> queryDictCode = new QueryWrapper<>(dcParam);
        return dictCodeRepository.list(queryDictCode);
    }
}
